import re


# -----------------------------------------------------------------------------
# Common precompiled regular expressions.
# -----------------------------------------------------------------------------
VALID_EMAIL = re.compile("""^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$""")

AREA_CODE = re.compile("[0-9][0-9][0-9]")

COMMA_OR_WS = re.compile(r'[\s|,]*', re.M)

HTML_TAG = re.compile(r'<[^>]*>', re.M)

URL_HANDLE = re.compile(r'^\/([^\/|\?|$]+)[^$]*')


# -----------------------------------------------------------------------------
# Units
# -----------------------------------------------------------------------------
if __name__ == "__main__":
	areacodes = ["413", "508", "abc", "1o1"]
	emails = [
		"username@yahoo.com", 
		"suername@somedomain.com", 
		"username@fas.harvard.edu", 
		"user.name@gat.com",
		"I-Should-fail"]
	
	print "Testing 'VALID_EMAIL': ", map(VALID_EMAIL.match, emails)
	print "Testing 'AREA_CODE': ", map(AREA_CODE.match, areacodes)
